package com.modbus.tool.entity.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import io.swagger.v3.oas.annotations.media.Schema;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.NonNull;

/**
 * @Author: Leno
 * @Date: 2025-08-07
 * @Description:
 */
@Data
@Schema(name = "Device对象", description = "Modbus设备表")
public class Device implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @Schema(description = "设备名称")
    @NotEmpty(message = "设备名称不能为空")
    private String name;

    @Schema(description = "协议类型: 0=TCP, 1=RTU, 2=RTU over TCP")
    @NotNull(message = "协议类型不能为空")
    private Byte protocolType;

    @Schema(description = "Modbus从站地址")
    @NotNull(message = "Modbus从站地址不能为空")
    private Short slaveAddress;

    @Schema(description = "寄存器起始地址")
    @NotNull(message = "寄存器起始地址不能为空")
    private Integer startAddress;

    @Schema(description = "读取寄存器数量")
    private Short registerCount;

    @Schema(description = "IP地址(协议类型0,2使用)")
    private String ipAddress;

    @Schema(description = "端口号(协议类型0,2使用)")
    private Integer port;

    @Schema(description = "串口设备路径(协议类型1使用)")
    private String serialPort;

    @Schema(description = "波特率(协议类型1使用)")
    private Integer baudRate;

    @Schema(description = "数据位数(协议类型1使用)")
    private Byte dataBits;

    @Schema(description = "校验方式(协议类型1使用)")
    private Integer parity;

    @Schema(description = "停止位(协议类型1使用)")
    private Integer stopBits;

    @Schema(description = "是否启用采集")
    private Boolean isActive;

    @Schema(description = "最后成功采集时间")
    private LocalDateTime lastSuccess;

    @Schema(description = "最后采集失败时间")
    private LocalDateTime lastError;

    @Schema(description = "错误详情")
    private String errorMessage;

    @Schema(description = "最后采集耗时(ms)")
    private Integer lastDuration;

    private LocalDateTime createdAt;

    private LocalDateTime updatedAt;


}

